package org.zfes.snowier.cloud.zbss.widget.act.service.impl;

import java.util.Map;
import java.util.Optional;
import org.zfes.snowier.core.data.DataSet;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.zfes.snowier.core.util.ZBeanUtil;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZAssert;
import org.zfes.snowier.common.dao.params.ParamMap;
import org.zfes.snowier.cloud.zbss.widget.act.service.IActSubjectJoinHisService;
import org.zfes.snowier.cloud.zbss.widget.act.dao.ActSubjectJoinHisMapper;
import org.zfes.snowier.cloud.zbss.widget.act.model.ActSubjectJoinHis;
import java.util.stream.Stream;
@Service
public class ActSubjectJoinHisServiceImpl implements IActSubjectJoinHisService{
 	@Autowired
	private ActSubjectJoinHisMapper actSubjectJoinHisMapper;
	
	@Transactional(rollbackFor=Exception.class)
 	@Override
	public void createActSubjectJoinHis(ActSubjectJoinHis actSubjectJoinHis) {
		ZBeanUtil.setCreateInfo(actSubjectJoinHis);
		ZBeanUtil.validateBean(actSubjectJoinHis);
		actSubjectJoinHisMapper.insertSelective(actSubjectJoinHis);
	}
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public Optional<ActSubjectJoinHis> loadActSubjectJoinHisById(Long id) {
		if(id!=null){
			return Optional.ofNullable(actSubjectJoinHisMapper.selectByPrimaryKey(id));
		}
		return Optional.empty();
		
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void updateActSubjectJoinHis(ActSubjectJoinHis actSubjectJoinHis) {
		ZBeanUtil.setUpdatedInfo(actSubjectJoinHis);
		ZBeanUtil.validateBean(actSubjectJoinHis);
		actSubjectJoinHisMapper.updateByPrimaryKeySelective(actSubjectJoinHis);
	}
	
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void deleteActSubjectJoinHis(Long id) {
		ZAssert.notNull(id, "请选择要操作的数据");
		actSubjectJoinHisMapper.deleteByPrimaryKey(id);
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void setActSubjectJoinHisStatus(Long id, Byte status) {
		ZAssert.notNull(id, "请选择要操作的数据");
		ZAssert.notNull(status, "状态参数错误");
		if(!Stream.of(new Byte[] {-1,0,1}).anyMatch(val->val.equals(status))) {
			ZAlert.serviceLogicalError("状态参数错误");
		}
		actSubjectJoinHisMapper.updateStatus( id,  status) ;
	}
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public DataSet loadActSubjectJoinHisDataSet(Map<String, Object> params) {
		ParamMap pm=ParamMap.filterParam(params);
		DataSet ds=DataSet.newDS2(actSubjectJoinHisMapper.selectListCount(pm), actSubjectJoinHisMapper.selectMapListPage(pm));
		return ds;
	}
	
}